<template>
	<view>
		<custom-header title="价格详情"></custom-header>
		<view style="display: flex; flex-direction: column; align-items: center; padding: 40rpx;">
			<image style="height: 250rpx; width: 250rpx;" :src="card.mimg" mode="aspectFit"></image>
			<view style="margin-top: 40rpx; font-size: 40rpx; color: black; font-weight: bold;">{{card.name}}</view>
		</view>

		<view class="popup-container">
			<view class="popup-header">
				<text class="title">今日报价</text>
			</view>

			<u-grid col="3" :border="false">
				<u-grid-item v-for="(item, index) in faceValueList" :key="index" @click="switchFace(index)">
					<view class="card-item-fv-container">
						<text class="card-item-state" v-if="isMaintain">维护中</text>
						<text class="card-item-name">￥{{item.faceValue == 0 ? "自定义" : item.faceValue}}</text>
						<view style="margin-top: 12rpx; font-size: 24rpx;">
							<text
								style="color: #626262; margin-right: 22rpx;">￥{{item.showAmount ? item.showAmount : '-'}}</text>
							<text style="color: #4D7EF4;">{{item.showRate ? item.showRate : '-'}}折</text>
						</view>
					</view>
				</u-grid-item>
			</u-grid>
		</view>
	</view>
</template>

<script>
	export default {
		onLoad() {
			const itemStr = uni.getStorageSync('selectedItem');
			this.card = JSON.parse(itemStr); // 反序列化对象
			console.log(this.card);
			uni.removeStorageSync('selectedItem'); // 清除缓存
			this.getFaceValue()
		},
		data() {
			return {
				card: null,
				faceValueList: [], //面值列表
			};
		},
		methods: {
			async getFaceValue() {
				const res = await this.$http({
					method: 'GET',
					url: '/product/faceValue/list',
					data: {
						prodId: this.card.id
					}
				});
				if (res) {
					this.faceValueList = res.data.filter(item => item.faceValue != 0);
				}
			},
		}
	}
</script>

<style lang="scss">
	.popup-container {
		overflow: auto;
		padding: 32rpx 28rpx;

		.popup-header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 46rpx;
			margin-left: 24rpx;

			.title {
				font-size: 28rpx;
				color: #000;
				font-weight: bold;
			}

			.close {
				height: 28rpx;
				width: 28rpx;
			}
		}

		.card-item-container {
			box-sizing: border-box;
			height: 154rpx;
			width: calc(100% - 32rpx);
			margin-bottom: 20rpx;
			position: relative;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			border: 2rpx solid #DCDCDC;
			border-radius: 14rpx;

			.item-image {
				height: 80rpx;
				width: 80rpx;
				margin-bottom: 14rpx;
			}

			.card-item-name {
				text-align: center;
				font-size: 24rpx;
				color: #171717;
			}
		}

		.card-item-fv-container {
			box-sizing: border-box;
			height: 118rpx;
			width: calc(100% - 20rpx);
			margin-bottom: 20rpx;
			position: relative;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			border: 2rpx solid #E5E5E5;
			border-radius: 14rpx;

			.card-item-name {
				text-align: center;
				font-size: 28rpx;
				color: #171717;
			}
		}

		.card-item-state {
			position: absolute;
			top: 0;
			right: 0;
			font-size: 20rpx;
			color: #fff;
			background-color: #ff4444;
			padding: 2rpx 10rpx;
			border-top-left-radius: 15px;
			/* 左上角 */
			border-bottom-right-radius: 15px;
			/* 右下角 */
		}
	}
</style>